package com.java46.admin.manager.action;

import com.java46.admin.base.action.BaseAction;
import com.java46.admin.manager.entity.ManagerEntity;
import com.java46.admin.manager.service.ManagerService;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import javax.servlet.http.HttpSession;


public class ManagerAction extends BaseAction {
    private String managerName;
    private String managerPassword;

    public String getManagerName() {
        return managerName;
    }

    public void setManagerName(String managerName) {
        this.managerName = managerName;
    }

    public String getManagerPassword() {
        return managerPassword;
    }

    public void setManagerPassword(String managerPassword) {
        this.managerPassword = managerPassword;
    }

    private ManagerService managerService = new ManagerService();
    @Action(value = "queryManager",results={
            @Result(name="success",location="/index.jsp"),
            @Result(name = "failed",location = "/detail/login.jsp")
    })
    /**
     * 登录
     */
    public String query_Manager(){
        ManagerEntity manager = managerService.query_Manager(managerName,managerPassword);
        if(manager != null){
            setSessionAttribute("manager",manager);
            return "success";
        }else{
            setSessionAttribute("error","用户名或者密码错误！");
            return "failed";
        }
    }
    @Action(value = "quit",results={
            @Result(name="success",location="/detail/login.jsp")
    })
    public String quit(){
        // 销毁session
        ServletActionContext.getRequest().getSession().invalidate();
        return "success";
    }
}
